<!--
 * @Author: 'yangyuhang1203' '2621131059@qq.com'
 * @Date: 2025-09-11 15:25:18
 * @LastEditors: 'yangyuhang1203' '2621131059@qq.com'
 * @LastEditTime: 2025-09-12 09:29:15
 * @FilePath: \企业级\前端\Vue\Axios请求.html
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="axios-0.18.0.js"></script>
</head>
<body>
<input type="button" value="获取数据GET" onclick="get()">
<input type="button" value="获取数据POST" onclick="post()">
</body>
    <script>
        function get(){
        //通过axios发送异步请求-get
        axios.get('http://127.0.0.1:4523/m1/7105129-6827067-default/user/getall')
        .then(function (response) {
        console.log(response);
        })
        .catch(function (error) {
        console.log(error);
        });
        }
        function post(){
        //通过axios发送异步请求-post
        const params = new URLSearchParams();
        params.append('username', "tom");
        params.append('password', "123456");
        axios.post('http://127.0.0.1:4523/m1/7105129-6827067-default/user/login', params, {
        // headers: {
        // 'Content-Type': 'application/x-www-form-urlencoded'
        // }
        })
        .then(function (response) {
        console.log(response.data);
        })
        .catch(function (error) {
        console.log(error);
        });
        }
    </script>
</html>